package edu.tgc.security;

import java.util.Collection;
import java.util.Properties;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

public class CustomInMemoryUserDetailsManager extends InMemoryUserDetailsManager {

    public CustomInMemoryUserDetailsManager() {
    }

    public CustomInMemoryUserDetailsManager(Collection<UserDetails> users) {
        super(users);
    }

    public CustomInMemoryUserDetailsManager(Properties users) {
        super(users);
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        try {
            UserDetails user = super.loadUserByUsername(username);
            return new SessionUser(user.getUsername(), user.getPassword(), user.getUsername(), user.isEnabled(), user.isAccountNonExpired(), user.isCredentialsNonExpired(), user.isAccountNonLocked(), user.getAuthorities());
        } catch (Exception e) {
            throw e;
        }
    }

}
